import axios from "axios";
import clone from "clone"
import { LifeCycleImp } from './abstract'

export class LifeCycle extends LifeCycleImp {
  store
  constructor(store) {
    super()
    this.store = store
  }
  created() {
    console.log('created......')
    this.store.beginEvents && this.store.beginEvents.map(eventCode => {
      this.store.eventCenter.fire(eventCode, {
        form: this.store.models,
        selector: this.store.selector.bind(this.store),
        triggerSource: '项目初始化created......',
        axios
      });
    })
  }
  beforeSubmit() {
    let _this = this
    return (function () {
      let form = null
      try {
        form = eval(_this.store.submitInterceptor)(_this.store.models)
      } catch (error) {
        form = _this.store.models
      }
      return  clone(form)
    })()
  }
  destroyed() {
    console.log('destroyed......')
  }
}